home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / sio.1.5.6 / suite / copytest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-09  |  4.2 KB  |  290 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. static char RCSid[] = "$Id: copytest.c,v 7.1 1992/06/01 21:38:57 panos Exp $" ;
  8.  
  9. #include "sio.h"
  10. #include <stdio.h>
  11. #include <syscall.h>
  12.  
  13.  
  14. /*************************************************************/
  15.  
  16. #ifdef TEST_Sread
  17.  
  18. #define BUFFER_SIZE  4096
  19.  
  20. main()
  21. {
  22.     char buf[ BUFFER_SIZE ] ;
  23.     int cc ;
  24.     int nbytes ;
  25.  
  26.     for ( ;; )
  27.     {
  28.         nbytes = random() & ( BUFFER_SIZE - 1 ) ;
  29.         if ( nbytes == 0 )
  30.             nbytes = 1 ;
  31.         cc = Sread( 0, buf, nbytes ) ;
  32.         if ( cc == 0 )
  33.             break ;
  34.         if ( cc == SIO_ERR )
  35.             exit( 1 ) ;
  36.         write( 1, buf, cc ) ;
  37.     }
  38.     exit( 0 ) ;
  39. }
  40. #endif /* TEST_Sread */
  41.  
  42. /*************************************************************/
  43.  
  44. #ifdef TEST_Swrite
  45.  
  46. #define BUFFER_SIZE  4096
  47.  
  48. main()
  49. {
  50.     char buf[ BUFFER_SIZE ] ;
  51.     int cc ;
  52.     int nbytes ;
  53.  
  54.     for ( ;; )
  55.     {
  56.         nbytes = random() & ( BUFFER_SIZE - 1 ) ;
  57.         if ( nbytes == 0 )
  58.             nbytes = 1 ;
  59.         cc = read( 0, buf, nbytes ) ;
  60.         if ( cc == 0 )
  61.             break ;
  62.         if ( Swrite( 1, buf, cc ) != cc )
  63.             exit( 1 ) ;
  64.     }
  65.     exit( 0 ) ;
  66. }
  67. #endif /* TEST_Swrite */
  68.  
  69. /*************************************************************/
  70.  
  71. #ifdef TEST_Srdline
  72.  
  73. main()
  74. {
  75.     char *s ;
  76.     int count=0 ;
  77.  
  78.     while ( s = Srdline( 0 ) )
  79.     {
  80.         puts( s ) ;
  81.         count++ ;
  82.     }
  83.     Sdone( 0 ) ;
  84.     exit( 0 ) ;
  85. }
  86.  
  87. #endif  /* TEST_Srdline */
  88.  
  89. /*************************************************************/
  90.  
  91. #ifdef TEST_Sputchar
  92.  
  93. main()
  94. {
  95.     int c ;
  96.  
  97.     while ( ( c = getchar() ) != EOF )
  98.         if ( Sputchar( 1, c ) != c )
  99.             exit( 1 ) ;
  100.     exit( 0 ) ;
  101. }
  102.  
  103. #endif /* TEST_Sputchar */
  104.  
  105. /*************************************************************/
  106.  
  107. #ifdef TEST_Sgetchar
  108.  
  109. main()
  110. {
  111.     int c ;
  112.  
  113.     while ( ( c = Sgetchar( 0 ) ) != SIO_EOF )
  114.         putchar( c ) ;
  115.     exit( 0 ) ;
  116. }
  117.  
  118. #endif    /* TEST_Sgetchar */
  119.  
  120. /*************************************************************/
  121.  
  122. #ifdef TEST_Sputc
  123.  
  124. main()
  125. {
  126.    int c ;
  127.  
  128.    while ( ( c = getchar() ) != EOF )
  129.       if ( Sputc( 1, c ) != c )
  130.          exit( 1 ) ;
  131.    exit( 0 ) ;
  132. }
  133.  
  134. #endif /* TEST_Sputc */
  135.  
  136. /*************************************************************/
  137.  
  138. #ifdef TEST_Sgetc
  139.  
  140. main()
  141. {
  142.    int c ;
  143.  
  144.    while ( ( c = Sgetc( 0 ) ) != SIO_EOF )
  145.       putchar( c ) ;
  146.    exit( 0 ) ;
  147. }
  148.  
  149. #endif /* TEST_Sgetc */
  150.  
  151. /*************************************************************/
  152.  
  153. #ifdef TEST_Sfetch
  154.  
  155. main()
  156. {
  157.     char *s ;
  158.     int len ;
  159.  
  160.     while ( s = Sfetch( 0, &len ) )
  161.         fwrite( s, 1, len, stdout ) ;
  162.     exit( 0 ) ;
  163. }
  164.  
  165. #endif /* TEST_Sfetch */
  166.  
  167. /*************************************************************/
  168.  
  169. #ifdef TEST_Sflush
  170.  
  171. #define MAX_COUNT        100
  172.  
  173. main()
  174. {
  175.     int c ;
  176.     int errval ;
  177.     int count = 0 ;
  178.     int max_count = random() % MAX_COUNT + 1 ;
  179.  
  180.     while ( ( c = getchar() ) != EOF )
  181.         if ( Sputchar( 1, c ) != c )
  182.             exit( errval ) ;
  183.         else
  184.         {
  185.             count++ ;
  186.             if ( count >= max_count )
  187.             {
  188.                 errval = Sflush( 1 ) ;
  189.                 if ( errval != 0 )
  190.                     exit( 1 ) ;
  191.                 max_count = random() % MAX_COUNT + 1 ;
  192.                 count = 0 ;
  193.             }
  194.         }
  195.     exit( 0 ) ;
  196. }
  197.  
  198. #endif /* TEST_Sflush */
  199.  
  200. /*************************************************************/
  201.  
  202. #ifdef TEST_Sundo
  203.  
  204. main()
  205. {
  206.     int c ;
  207.     char *s ;
  208.     int errval ;
  209.  
  210.     for ( ;; )
  211.     {
  212.         if ( random() % 1 )
  213.         {
  214.             s = Srdline( 0 ) ;
  215.             if ( s == NULL )
  216.                 break ;
  217.             if ( random() % 16 < 5 )
  218.             {
  219.                 errval = Sundo( 0, SIO_UNDO_LINE ) ;
  220.                 if ( errval == SIO_ERR )
  221.                     exit( 1 ) ;
  222.             }
  223.             else
  224.                 puts( s ) ;
  225.         }
  226.         else
  227.         {
  228.             c = Sgetchar( 0 ) ;
  229.             if ( c == SIO_EOF )
  230.                 break ;
  231.             if ( random() % 16 < 5 )
  232.             {
  233.                 errval = Sundo( 0, SIO_UNDO_CHAR ) ;
  234.                 if ( errval == SIO_ERR )
  235.                     exit( 2 ) ;
  236.             }
  237.             else
  238.                 putchar( c ) ;
  239.         }
  240.     }
  241.     exit( 0 ) ;
  242. }
  243.  
  244. #endif /* TEST_Sundo */
  245.  
  246.  
  247. #if defined( TEST_switch ) || defined( TEST_switch2 )
  248.  
  249. main()
  250. {
  251.     int c ;
  252.     char *s ;
  253.     int lines = 4000 ;
  254.  
  255.     for ( ;; )
  256.     {
  257.         c = Sgetchar( 0 ) ;
  258.         if ( c == SIO_EOF )
  259.             exit( 0 ) ;
  260.         if ( c == SIO_ERR )
  261.             exit( 1 ) ;
  262.         putchar( c ) ;
  263.         if ( c == '\n' )
  264.         {
  265.             lines-- ;
  266.             if ( lines == 0 )
  267.                 break ;
  268.         }
  269.     }
  270.     while ( s = Srdline( 0 ) )
  271.         puts( s ) ;
  272.     exit( 0 ) ;
  273. }
  274.  
  275. #ifdef TEST_switch2
  276.  
  277. char *mmap( addr, len, prot, type, fd, off )
  278.     char *addr ;
  279.     int len, prot, type, fd, off ;
  280. {
  281.     return( (char *)-1 ) ;
  282. }
  283.  
  284. #endif    /* TEST_switch2 */
  285.  
  286. #endif     /* TEST_switch */
  287.  
  288.  
  289.  
  290.